//
//  BaseViewController.m
//  XTXOneToOne
//
//  Created by Canny on 2018/10/29.
//  Copyright © 2018年 WK. All rights reserved.
//

#import "BaseViewController.h"

@interface BaseViewController ()

@property(nonatomic,strong)UILabel * bTitle;

@end

@implementation BaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self createBackBtn];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    _bTitle = [[UILabel alloc] init];
    _bTitle.text = @"";
    _bTitle.font = [UIFont boldSystemFontOfSize:16];
    _bTitle.textColor = RGB(30, 63, 89);
    [self.view addSubview:_bTitle];
    _bTitle.textAlignment = NSTextAlignmentCenter;
    
    [_bTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top).offset(TopBackButtonHeight);
        make.centerX.equalTo(self.view.mas_centerX);
        make.width.equalTo(@(100));
        make.height.equalTo(@(32));
    }];
    
    
    _rightBtn = [[UIButton alloc] init];
    [_rightBtn setTitle:@"" forState:UIControlStateNormal];
    _rightBtn.titleLabel.font = [UIFont boldSystemFontOfSize:16];
    [_rightBtn setTitleColor:RGB(30, 63, 89) forState:UIControlStateNormal];
    [self.view addSubview:_rightBtn];
    _rightBtn.backgroundColor=MC_TEST_COLOR;
    _rightBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    [_rightBtn addTarget:self action:@selector(rightAction) forControlEvents:UIControlEventTouchUpInside];
    [_rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top).offset(TopBackButtonHeight);
        make.right.equalTo(self.view.mas_right).offset(-20);
        make.width.equalTo(@(80));
        make.height.equalTo(@(32));
    }];
    
    
    
    
    
    UIView * bgView = [[UIView alloc]init];
    [self.view addSubview:bgView];
    bgView.backgroundColor = [UIColor whiteColor];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top).offset(kStatusBarAndNavigationBarHeight);
        make.right.left.bottom.equalTo(self.view);
    }];
    _bgView=bgView;
    
    UITapGestureRecognizer *singleTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeKeyboard:)];
    singleTapGesture.numberOfTapsRequired = 1;
    singleTapGesture.cancelsTouchesInView = NO;
    [bgView  addGestureRecognizer:singleTapGesture];

}

#pragma mark - gesture actions
- (void)closeKeyboard:(UITapGestureRecognizer *)recognizer {
    [self.view endEditing:YES];
    //    [self.viewPop hiden];
}


-(void)setBaseVcTitle:(NSString *)baseVcTitle{
    _baseVcTitle = baseVcTitle;
    _bTitle.text = baseVcTitle;
}

-(void)createBackBtn{
    UIButton * backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [backBtn setTitle:@"" forState:UIControlStateNormal];
    [backBtn setTitleColor:RGB(255, 255, 255) forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(goBackAction) forControlEvents:UIControlEventTouchUpInside];
    backBtn.imageView.frame=CGRectMake(0, 0, 18, 32);
    [backBtn setImage:[UIImage imageNamed:@"图层-6"] forState:UIControlStateNormal];
    [self.view addSubview:backBtn];
    backBtn.backgroundColor=MC_TEST_COLOR;
    backBtn.tag=7002;
    backBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    backBtn.titleLabel.font=[UIFont systemFontOfSize:15];
    [backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top).offset(TopBackButtonHeight);
        make.left.equalTo(self.view.mas_left).offset(-20);
        
        make.height.equalTo(@(32));
        make.width.equalTo(@(100));
    }];
}

-(void)goBackAction{
    [self.navigationController popViewControllerAnimated:YES];
}



-(void)rightAction{
    
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
